using System.Globalization;

namespace Foundation.FileAssotiations
{
    /// <summary>
    /// Program Icon.
    /// </summary>
    public class ProgramIcon
    {
        /// <summary>
        /// Gets or sets value that specifies icons index within a file.
        /// </summary>
        public int Index { get; set; }

        /// <summary>
        /// Gets or sets a value that specifies the file containing the icon.
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// Parses string to create and instance of ProgramIcon.
        /// </summary>
        /// <param name="registryString">String specifying file path. Icon can be included as well.</param>
        /// <returns>ProgramIcon based on input string.</returns>
        public static ProgramIcon Parse(string registryString)
        {
            if (string.IsNullOrEmpty(registryString))
                return new ProgramIcon();

            var values = registryString.Split(',');
            var path = values.Length > 0 ? values[0] : null;
            var index = values.Length > 1 ? int.Parse(values[1]) : 0;
            return new ProgramIcon { Path = path, Index = index };
        }

        /// <summary>
        /// Returns string representation of current ProgramIcon.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.IsNullOrEmpty(Path)
                       ? string.Empty
                       : string.Format("{0},{1}", Path, Index.ToString(CultureInfo.InvariantCulture));
        }
    }
}